<template>
    <div class="top-banner">
      <div class="logo-container">
        <div class="logo-title">互联网应用服务</div>
        <div class="version">V 1.0</div>
      </div>

      <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="hover">
        <div class="avatar-wrapper">
          <div class="banner-user-avatar" v-if="user.nickName">{{ user.nickName[0] }}</div>
          <div>{{user.nickName}}</div>
          <i class="el-icon-caret-bottom" style="margin-left: 10px !important;"/>
        </div>
        <el-dropdown-menu slot="dropdown">
          <router-link to="/">
            <el-dropdown-item>首页</el-dropdown-item>
          </router-link>
          <router-link to="/user/profile">
            <el-dropdown-item>个人中心</el-dropdown-item>
          </router-link>
          <el-dropdown-item divided @click.native="logout">
            <span>退出登录</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
</template>

<script>
  import { getUserProfile } from "@/api/system/user";
  export default {
    name: "index",
    data() {
      return {
        user: {}
      }
    },
    mounted() {
      this.getUser()
    },
    methods: {
      getUser() {
        getUserProfile().then(res => {
          this.user = res.data;
        });
      },
      async logout() {
        this.$confirm('确定注销并退出系统吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$store.dispatch('LogOut').then(() => {
            location.href = '/index';
          })
        }).catch(() => {});
      }
    }
  }
</script>

<style lang="scss">
  @import "~@/assets/styles/mixin.scss";
  @import "~@/assets/styles/variables.scss";
  .banner-user-avatar {
    float: left;
    width: 26px;
    height: 26px;
    margin-right: 6px;
    line-height: 26px;
    text-align: center;
    background-color: #409EFF;
    border-radius: 50%;
    border: 1px solid #fff;
  }

  .app-wrapper {
    @include clearfix;
    position: relative;
    height: 100%;
    width: 100%;
    margin-top: 56px;

    &.mobile.openSidebar {
      position: fixed;
      top: 0;
    }
  }

  .top-banner {
    position: fixed;
    height: 56px;
    width: 100vw;
    background-color: #031A2E;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 2;

    .logo-container {
      display: flex;
      align-items: center;

      .logo-title {
        font-family: PangMenZhengDao;
        font-size: 18px;
        color: #FFFFFF;
        margin-right: 12px;
        margin-left: 32px;
      }

      .version {
        background-image: linear-gradient(270deg, #76C0FF 0%, #1B58FF 100%);
        border-radius: 4px;
        font-family: Tensentype-RuiHeiJ-W5;
        font-size: 12px;
        color: #FFFFFF;
        letter-spacing: 0;
        text-align: center;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 3px 8px;
      }
    }

    .avatar-container {
      margin-right: 32px;
      position: relative;

      .avatar-wrapper {
        margin-top: 5px;
        position: relative;
        display: flex;
        align-items: center;
        font-family: PingFangSC-Medium;
        font-size: 14px;
        color: #FFFFFF;
        letter-spacing: 0;

        .user-avatar {
          cursor: pointer;
          width: 30px;
          height: 30px;
          border-radius: 15px;
          margin-right: 13px;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          margin-left: 56px;
          /*position: absolute;
          right: -20px;
          top: 25px;*/
          font-size: 12px;
        }
      }
    }
  }
</style>
